# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4

##
## Copyright (C) 2009 - George Y. Kussumoto <georgeyk.dev@gmail.com>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., or visit: http://www.gnu.org/.
##
##

import random

import google.appengine.ext.db as db


class HeroClass(db.Model):
    """Hero Class object implementation.
    #TODO: improve docstrings

    @ivar: hero class name
    """
    name = db.StringProperty(required=True)


class Hero(db.Model):
    """Hero object implementation.
    #TODO: improve docstrings

    @ivar name: hero name
    @ivar xp: Experience Points
    @ivar level: hero level
    @ivar hp: hero health
    @ivar strg: hero strength
    @ivar const: hero constitution
    @ivar dex: hero dexterity
    @ivar intl: hero intelligence
    @ivar wsd: hero wisdom
    @ivar cha: hero charisma
    """
    name = db.StringProperty(required=True)
    xp = db.IntegerProperty(required=True, default=1)
    level = db.IntegerProperty(required=True, default=1)
    heroclass = db.ReferenceProperty(HeroClass, required=True)

    hp = db.IntegerProperty(required=True, default=1)
    strg = db.IntegerProperty(required=True, default=1)
    const = db.IntegerProperty(required=True, default=1)
    dex = db.IntegerProperty(required=True, default=1)
    intl = db.IntegerProperty(required=True, default=1)
    wsd = db.IntegerProperty(required=True, default=1)
    cha = db.IntegerProperty(required=True, default=1)

    @classmethod
    def get_attributes(self):
        #FIXME: crap code
        return [u'hp',
                'strg',
                'const',
                'dex',
                'intl',
                'wsd',
                'cha',]

    def update(self):
        self.xp += 1
        if self.xp > 10*pow(1.16, self.level):
            self.level += 1
            a = random.randint(1, 7)
            if a == 1:
                self.hp += 1
            elif a == 2:
                self.strg += 1
            elif a == 3:
                self.const += 1
            elif a == 4:
                self.dex += 1
            elif a == 5:
                self.intl += 1
            elif a == 6:
                self.wsd += 1
            elif a == 7:
                self.cha += 1

        self.put()
        return
